//
// Created by Semir on 2020/4/2.
//

#include <iostream>

using namespace std;

const int MAX_V = 20000;
const int MAX_N = 30;
int cap, n;
int v[MAX_N];
int dp[MAX_V] = {0};

void plan() {
    for (int i = 1; i <= n; i++) {
        for (int j = cap; j >= v[i]; j--) {
            dp[j] = max(dp[j - v[i]] + v[i], dp[j]);
        }
    }
}

int main() {
    cin >> cap >> n;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    plan();
    int res = cap - dp[cap];
    cout << res << endl;
    return 0;
}
